package ExampleCollections;

import HashSet_1.Student;

import java.util.*;

/**
 * 业务：
 * 班级考试的C语言成绩是:
 * 87 98 69 60  76  90 56 78
 * 把成绩低于80分过滤掉
 * 逻辑
 */
public class List1 {
    public static void main(String[] args) {
        List1 list1 = new List1();
        // list1.scoreList();
        //list1.studentList();
        //list1.arrayToList();
//        list1.changeList();
        list1.listVers();
    }

    public void scoreList() {
        ArrayList<Integer> scores = new ArrayList<>();
        scores.add(87);
        scores.add(98);
        scores.add(69);
        scores.add(60);
        scores.add(76);
        scores.add(90);
        scores.add(56);
        scores.add(78);
        System.out.println("------原始的C语言成绩----");
        for (Integer ele : scores) {
            System.out.println("ele = " + ele);
        }

        for (int i = 0; i < scores.size(); i++) {
            if (scores.get(i) < 80) {
                scores.remove(i);
                i--;
            }
        }
        System.out.println("过滤80分之后的成绩如下：");
        for (Integer ele : scores) {
            System.out.println("ele = " + ele);
        }

    }

    /*

        集合中存储自定义类型
     */
    public void studentList() {
        Student student1 = new Student("aaa", 18);
        Student student2 = new Student("bbb", 17);
        Student student3 = new Student("ccc", 19);
        ArrayList<Student> students = new ArrayList<>();
        students.add(student1);
        students.add(student2);
        students.add(student3);
        //System.out.println("students = " + students);
        for (int i = 0; i < students.size(); i++) {
            System.out.println("students.get(" + i + ") = " + students.get(i));
        }

        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            System.out.println("iterator.next() = " + iterator.next());
        }
    }

    /*
    数组转集合
     */
    public void arrayToList() {//"0"  "1"  "2"
        int total = 10;
        String[] strings = new String[total];
        for (int i = 0; i < strings.length; i++) {
            strings[i] = String.valueOf(i);
        }
        //把strings数组转成集合
        List<String> strings1 = Arrays.asList(strings);
        for (String ele : strings1) {
            System.out.println("ele = " + ele);
        }
        System.out.println("向转换之后的集合框架中添加字符串");
//        strings1.add("xyz");
//        strings1.add("123");
        for (String ele : strings1) {
            System.out.println("ele = " + ele);
        }

    }


    /**
     * 集合乱序输出
     */
    public void changeList() {
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            integers.add(i);
        }
        for (int i = 0; i < 3; i++) {
            System.out.println("打乱前");
            System.out.println("integers = " + integers);
            Collections.shuffle(integers);
            System.out.println("打乱后");
            System.out.println("integers = " + integers);
            System.out.println("-----------------------");
            Collections.sort(integers);
            System.out.println("排序后");
            System.out.println("integers = " + integers);
        }
    }
    public void listVers()
    {
        String[] names = {"java", "php", "python", "c++"};
        List<String> strings = Arrays.asList(names);
        Iterator<String> iterator = strings.iterator();
        System.out.println("翻转前");
        Collections.sort(strings);//ASCII
        while(iterator.hasNext())
        {
            System.out.println(iterator.next());
        }

        System.out.println("翻转后");
        Collections.reverse(strings);

        Iterator<String> iterator1 = strings.iterator();
        while(iterator1.hasNext())
        {
            System.out.println(iterator1.next());
        }


    }
}